# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Robin Candau <antiz@archlinux.org>
# Contributor: Eric Berquist <eric dot berquist at gmail dot com>

pkgname=markdownlint
_pkgname=mdl
pkgver=0.13.0
pkgrel=1
pkgdesc='A lint tool to check markdown files and flag style issues'
arch=('any')
url='https://github.com/markdownlint/markdownlint'
license=('MIT')
depends=(
  'ruby'
  'ruby-kramdown'
  'ruby-kramdown-parser-gfm'
  'ruby-mixlib-cli'
  'ruby-mixlib-config'
  'ruby-mixlib-shellout'
)
makedepends=('git' 'ruby-rdoc')
provides=('ruby-mdl')
replaces=('ruby-mdl')
options=('!emptydirs')
_commit='54b2597eb40d50a16a51d717744239d52218fd5b'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # we do not do version pinning
  sed --regexp-extended 's,~>,>=,g' --in-place *.gemspec Gemfile Rakefile
}

build() {
  cd "$pkgname"

  gem build "$_pkgname.gemspec"
}

package() {
  local _gemdir="$(ruby -e'puts Gem.default_dir')"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --no-document \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$pkgname/$_pkgname-$pkgver.gem"

  # delete cache
  rm -vrf "$pkgdir/$_gemdir/cache"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname"
}
